#!/usr/bin/env bash

CMAKE_CMDS=$(cat <<EOF | tr '\n' '|'
BREAK
CMAKE_HOST_SYSTEM_INFORMATION
CMAKE_LANGUAGE
CMAKE_MINIMUM_REQUIRED
CMAKE_PARSE_ARGUMENTS
CMAKE_POLICY
CONFIGURE_FILE
CONTINUE
ELSEIF
ENDFOREACH
ENDFUNCTION
ENDMACRO
ENDWHILE
EXECUTE_PROCESS
FILE
FIND_FILE
FIND_LIBRARY
FIND_PACKAGE
FIND_PATH
FIND_PROGRAM
FOREACH
FUNCTION
GET_CMAKE_PROPERTY
GET_DIRECTORY_PROPERTY
GET_FILENAME_COMPONENT
GET_PROPERTY
IF
INCLUDE
INCLUDE_GUARD
LIST
MACRO
MARK_AS_ADVANCED
MATH
MESSAGE
OPTION
RETURN
SEPARATE_ARGUMENTS
SET
SET_DIRECTORY_PROPERTIES
SET_PROPERTY
SITE_NAME
STRING
UNSET
VARIABLE_WATCH
WHILE
ADD_COMPILE_DEFINITIONS
ADD_COMPILE_OPTIONS
ADD_CUSTOM_COMMAND
ADD_CUSTOM_TARGET
ADD_DEFINITIONS
ADD_DEPENDENCIES
ADD_EXECUTABLE
ADD_LIBRARY
ADD_LINK_OPTIONS
ADD_SUBDIRECTORY
ADD_TEST
AUX_SOURCE_DIRECTORY
BUILD_COMMAND
CREATE_TEST_SOURCELIST
DEFINE_PROPERTY
ENABLE_LANGUAGE
ENABLE_TESTING
EXPORT
FLTK_WRAP_UI
GET_SOURCE_FILE_PROPERTY
GET_TARGET_PROPERTY
GET_TEST_PROPERTY
INCLUDE_DIRECTORIES
INCLUDE_EXTERNAL_MSPROJECT
INCLUDE_REGULAR_EXPRESSION
INSTALL
LINK_DIRECTORIES
LINK_LIBRARIES
LOAD_CACHE
PROJECT
REMOVE_DEFINITIONS
SET_SOURCE_FILES_PROPERTIES
SET_TARGET_PROPERTIES
SET_TESTS_PROPERTIES
SOURCE_GROUP
TARGET_COMPILE_DEFINITIONS
TARGET_COMPILE_FEATURES
TARGET_COMPILE_OPTIONS
TARGET_INCLUDE_DIRECTORIES
TARGET_LINK_DIRECTORIES
TARGET_LINK_LIBRARIES
TARGET_LINK_OPTIONS
TARGET_PRECOMPILE_HEADERS
TARGET_SOURCES
TRY_COMPILE
TRY_RUN
CTEST_BUILD
CTEST_CONFIGURE
CTEST_COVERAGE
CTEST_EMPTY_BINARY_DIRECTORY
CTEST_MEMCHECK
CTEST_READ_CUSTOM_FILES
CTEST_RUN_SCRIPT
CTEST_SLEEP
CTEST_START
CTEST_SUBMIT
CTEST_TEST
CTEST_UPDATE
CTEST_UPLOAD
EOF
)

echo $CMAKE_CMDS

find . -iname CMakeLists.txt | xargs \
gsed -i -r "s/\b((${CMAKE_CMDS}) *\()/\L\1/g; s/(ELSE|ENDIF) *\(.*\)/\L\1()/"
